package com.chaopei.activemq_provider.controller;

import com.chaopei.activemq_provider.service.ProviderService;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author Corday 天涯
 * @Date 2022/5/14 21:50
 */
@RestController
public class ProdviderController {
    @Resource
    private ProviderService providerService;
    @Resource
    private JmsMessagingTemplate jmsMessagingTemplate;

    /**
     * http://localhost:9081/go?msg=hellome
     *
     * @param msg
     * @return
     */
    @RequestMapping("/go")
    public String go(String msg) {
        boolean flag = providerService.update(msg);
        if (flag) {
            jmsMessagingTemplate.convertAndSend("tom", "content:"+msg);
            return "消息发送成功...";
        }
        return "系统有误,稍候刷新...";
    }
}
